package com.csun.dsms.utils;

import java.util.ArrayList;
import java.util.List;

public class DataUtils {

    public static Boolean listIfHaveInteger(List<Integer> fields, Integer i) {
        for (Integer field : fields) {
            if (i.equals(field)){
                return true;
            }
        }
        return false;
    }

    public static Boolean listIfHaveLong(List<Long> fields, Long i) {
        for (Long field : fields) {
            if (i.equals(field)){
                return true;
            }
        }
        return false;
    }

    public static Integer getPointerToInteger(List<Integer> fields, Integer data) {
        for (int i = 0; i < fields.size(); i++) {
            if (fields.get(i).equals(data)){
                return i;
            }
        }
        return null;
    }

    public static List<Long> getCommunityIdsToList(String communityIdsString){
        ArrayList<Long> communityIds = new ArrayList<>();
        String[] split = communityIdsString.split("&");
        for (int i = 0; i < split.length; i++) {
            communityIds.add(Long.parseLong(split[i]));
        }
        return communityIds;
    }

    public static String getCommunityIdsToString(List<Long> communityIds){
        String communityIdsString = ""+communityIds.get(0);
        for (int i = 1; i < communityIds.size(); i++) {
            communityIdsString=communityIdsString+"&"+communityIds.get(i);
        }
        return communityIdsString;
    }
}
